import React, { Component } from 'react';
import CustomBreadcrumb from '../../components/CustomBreadcrumb';
import EditChannelForm from './components/EditChannelForm';
import { hashHistory } from 'react-router';
import { ChannelService } from '../../services'

export default class EditChannel extends Component {
  static displayName = 'EditChannel';

  constructor(props) {
    super(props);
    this.state = {
      value : {
        ...this.props.location.state,
        id : this.props.params.id,
      }
    };
  }

  onSubmit = async(data) =>{
    await ChannelService.update(data)
    hashHistory.push('/channel/list')
    return true
  }

  render() {
    const breadcrumb = [
      { text: '渠道管理', link: '#/channel/list' },
      { text: '修改渠道', link: null },
    ];
    return (
      <div className="addchannel-page">
        <CustomBreadcrumb dataSource={breadcrumb} />
        <EditChannelForm value={this.state.value} onSubmit={this.onSubmit}/>
      </div>
    );
  }
}
